<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('基金分配') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('分配类型')" prop="fpType">
        <el-select v-model="queryParams.fpType" :placeholder="$t('分配类型')" clearable>
          <el-option
            v-for="dict in fpTypeOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <!--<el-form-item label="分配批次" prop="fpQc">
        <el-input
          v-model="queryParams.fpQc"
          placeholder="请输入分配批次"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索")
        }}
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fund:fp:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t("新增") }}
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fund:fp:edit']"
          type="primary"
          icon="el-icon-upload"
          size="mini"
          @click="initData(1)"
        >{{ $t('导入分配详情') }}
        </el-button>
        <el-button
          type="success"
          size="mini"
          @click="hurdleOpen=true"
        >{{ $t('Hurdle测算') }}</el-button>
        <el-button
          v-hasPermi="['lp:LpPublicBulletin:edit']"
          type="success"
          size="mini"
          @click="setMessageTemplate"
        >{{ $t('通知内容模板') }}</el-button>
        <!--<el-button-->
        <!--  v-hasPermi="['system:word:edit']"-->
        <!--  type="warning"-->
        <!--  size="mini"-->
        <!--  @click="setTemplate"-->
        <!--&gt;{{ $t('通知文件模板') }}</el-button>-->
      </el-col>
      <!--<el-col :span="1.5">
        <el-button
          v-hasPermi="['fp:fp:export']"
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportHandle"
        >{{ $t("导出") }}</el-button>
      </el-col>-->
    </el-row>

    <el-table v-loading="loading" :data="fundFpMainList" :show-summary="true" :summary-method="getSummaries" border tooltip-effect="darkTable">
      <el-table-column :label="$t('分配批次')" align="center" prop="fpQc" show-overflow-tooltip width="120" />
      <el-table-column
        :label="$t('分配类型')"
        align="center"
        prop="fpType"
        :formatter="fpTypeFormat"
        show-overflow-tooltip
        width="250"
      />
      <el-table-column :label="$t('分配时间')" align="center" prop="fpTime" show-overflow-tooltip width="140">
        <template slot-scope="scope">
          <span class="link-type" @click="updateHandle(scope.row)">{{ parseTime(scope.row.fpTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('分配总金额') + $t('金额单位')"
        header-align="center"
        align="right"
        prop="fpTotalAmount"
        show-overflow-tooltip
        width="140"
      >
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.fpTotalAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('分配明细总额') + $t('金额单位')"
        header-align="center"
        align="right"
        prop="totalAllocationDetails"
        show-overflow-tooltip
        width="140"
      >
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.totalAllocationDetails, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('备注')" align="center" prop="remark" show-overflow-tooltip />
      <el-table-column v-if="useProcess" :label="$t('审批状态')" align="center" width="120">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('操作')"
        fixed="right"
        align="center"
        class-name="small-padding fixed-width"
        width="400"
      >
        <template slot-scope="scope">
          <!--
          <el-button
            v-hasPermi="['fund:fp:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="allocation(scope.row)"
          >{{ $t('分配') }}
          </el-button>
          -->
          <span style="display: none">{{ useProcess }}</span>
          <div v-if="useProcess">
            <ListBtn v-if="useProcess" :bus-data="scope.row" has-permi="fund:fp">
              <template v-slot:before>
                <el-button
                  v-if="(scope.row.actStatus === 'W' || scope.row.actStatus === 'D') && scope.row.announcementId"
                  size="small"
                  type="text"
                  icon="el-icon-s-promotion"
                  @click="noticeHandle(scope.row)"
                >{{ $t('通知详情') }}</el-button>
                <el-button
                  v-if="scope.row.actStatus !== 'W' && scope.row.actStatus !== 'D' && scope.row.id !== undefined && scope.row.id !== null && scope.row.id !== ''"
                  v-hasPermi="['fund:fp:edit']"
                  size="small"
                  type="text"
                  icon="el-icon-s-tools"
                  @click="sendHandle(scope.row, scope.$index)"
                >{{ $t('通知配置') }}</el-button>
                <el-button
                  v-hasPermi="['fund:fp:edit']"
                  size="small"
                  type="text"
                  icon="el-icon-edit"
                  @click="openDetails(scope.row)"
                >{{ $t('分配明细') }}</el-button>
              </template>
            </ListBtn>
          </div>
          <!-- 未开启流程 -->
          <div v-if="!useProcess">
            <el-button
              v-if="scope.row.status === '已发送' && scope.row.announcementId"
              size="small"
              type="text"
              icon="el-icon-s-promotion"
              @click="noticeHandle(scope.row)"
            >{{ $t('通知详情') }}</el-button>
            <el-button
              v-if="(scope.row.actStatus !== 'W' && scope.row.actStatus !== 'D' && scope.row.id !== undefined && scope.row.id !== null && scope.row.id !== '') && (scope.row.status === '待复核')"
              v-hasPermi="['fund:fp:edit']"
              size="small"
              type="text"
              icon="el-icon-s-tools"
              @click="noticeHandle(scope.row)"
            >{{ $t('复核通知') }}</el-button>
            <el-button
              v-if="(scope.row.actStatus !== 'W' && scope.row.actStatus !== 'D' && scope.row.id !== undefined && scope.row.id !== null && scope.row.id !== '') && (scope.row.status !== '待复核' && scope.row.status !== '已发送')"
              v-hasPermi="['fund:fp:edit']"
              size="small"
              type="text"
              icon="el-icon-s-tools"
              @click="sendHandle(scope.row, scope.$index)"
            >{{ $t('通知配置') }}</el-button>
            <el-button
              v-hasPermi="['fund:fp:edit']"
              size="small"
              type="text"
              icon="el-icon-edit"
              @click="openDetails(scope.row)"
            >{{ $t('分配明细') }}</el-button>
            <el-button
              v-if="!useProcess"
              v-hasPermi="['fund:fp:edit']"
              size="small"
              type="text"
              icon="el-icon-edit"
              @click="updateHandle(scope.row)"
            >{{ $t('修改') }}</el-button>
            <el-button
              v-if="!useProcess"
              v-hasPermi="['fund:fp:remove']"
              size="small"
              type="text"
              icon="el-icon-delete"
              @click="deleteHandle(scope.row)"
            >{{ $t('删除') }}</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :title="$t('公示内容')" :visible.sync="publicityOpen" :destroy-on-close="true" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <afficheForm v-if="publicityOpen" ref="afficheForm" parent-business-type="fundFpMain" :call-init-status="callInitStatus" :call-money-use-process="useProcess" :show-save-btn="showAfficheSaveBtn" @notNullAfffiche="notNullAfffiche" />
    </el-dialog>

    <!-- 导入窗口 -->
    <el-dialog
      :title="$t('导入')"
      :visible.sync="upload.open"
      width="400px"
      :close-on-click-modal="false"
      :lock-scroll="false"
      append-to-body
    >
      <div>
        <el-form ref="form" label-width="120px" :rules="rules" class="dataForm pr-0">
          <el-col :span="24">
            <el-form-item :label="$t('分配批次')" prop="fpQc">
              <el-select
                v-model="upload.headers.fpQc"
                :placeholder="$t('分配批次')"
                style="width: 100%"
                clearable
              >
                <el-option
                  v-for="dict in fpQcList"
                  :key="dict.fpQc"
                  :label="$t(dict.fpQc)"
                  :value="dict.fpQc"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
        <el-upload
          ref="upload"
          :limit="1"
          accept=".xlsx, .xls"
          :headers="upload.headers"
          :action="upload.url"
          :disabled="upload.isUploading"
          :on-progress="handleFileUploadProgress"
          :on-success="handleFileSuccess"
          :on-exceed="handleFileExceed"
          :auto-upload="false"
          drag
        >
          <div slot="tip" class="el-upload__tip" style="color:red">
            {{ $t('提示：仅允许导入“xls”或“xlsx”格式文件！') }}
            <el-link type="primary" style="font-size:12px" @click="fetchTemplate">
              {{ $t('下载模板') }}
            </el-link>
          </div>
          <i class="el-icon-upload" />
          <div class="el-upload__text">
            {{ $t(' 将文件拖到此处，或') }}
            <em>{{ $t('点击上传') }}</em>
          </div>

        </el-upload>

        <div slot="footer" class="dialog-footer" style="text-align: right;">
          <el-button @click="upload.open = false">{{ $t("取消") }}</el-button>
          <el-button type="primary" @click="submitFileForm">{{ $t("确定") }}</el-button>
        </div>
      </div>
    </el-dialog>

    <!-- 添加或修改基金分配主表对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="formFpOpen"
      :close-on-click-modal="false"
      :lock-scroll="false"
      :destroy-on-close="true"
      custom-class="dialogForm"
      append-to-body
    >
      <fundFpMainForm ref="fundFpMainForm" />
    </el-dialog>
    <!-- 基金分配明细对话框 -->
    <el-dialog
      :title="detailsTitle"
      :visible.sync="detailsOpen"
      :close-on-click-modal="false"
      :lock-scroll="false"
      :destroy-on-close="true"
      custom-class="dialogView"
      append-to-body
    >
      <fundFundFpSourceList ref="fundFundFpSourceList" />
    </el-dialog>
    <!-- 基金分配明细对话框, 根据出资人分组合计的数据 -->
    <el-dialog
      :title="detailsGroupTitle"
      :visible.sync="detailsGroupOpen"
      :close-on-click-modal="false"
      :lock-scroll="false"
      :destroy-on-close="true"
      custom-class="dialogView"
      append-to-body
    >
      <fund-fp-group-investor ref="fundFpGroupInvestor" :other-btn-hide="otherBtnHide" />
    </el-dialog>

    <!-- 补亏项目列表对话框 -->
    <el-dialog
      :title="lossTitle"
      :visible.sync="lossOpen"
      :close-on-click-modal="false"
      :lock-scroll="false"
      :destroy-on-close="true"
      custom-class="dialogForm"
      append-to-body
    >
      <fundFpLossDealList ref="fundFpLossDealList" />
    </el-dialog>

    <!-- 模板form页面 -->
    <div>
      <div v-show="keyWordFormLoading" style="text-align: center">
        <i class="el-icon-loading" style="font-size: 30px;color: #ffffff;z-index: 6002 !important;position: absolute;margin-top: -20vh;" />
        {{ $t('正在生成各出资人的文档') }}
      </div>
      <el-dialog :title="keyWordTitle" :visible.sync="keyWordFormLoading" width="600px" :close-on-click-modal="false" custom-class="dialogForm dialogFormCustom" append-to-body>
        <wordOnlineTemplateForm ref="wordOnlineTemplateForm" @templateFormCancel="templateFormCancel" />
      </el-dialog>
    </div>

    <!-- 模板列表 -->
    <el-dialog :title="keyWordTitle" :visible.sync="keyWordLoading" :close-on-click-modal="false" custom-class="dialogForm" append-to-body>
      <wordOnlineTemplateList ref="wordOnlineTemplateList" @saveSelectTemplate="saveSelectTemplate" />
    </el-dialog>

    <el-dialog :title="$t('模板维护')" :visible.sync="templateOpen" :destroy-on-close="true" :close-on-click-modal="false" custom-class="dialogForm" append-to-body>
      <afficheTemplateForm v-if="templateOpen" ref="afficheTemplateForm" parent-template-type="fundFpMain" />
    </el-dialog>

    <el-dialog :title="$t('公告审核')" :visible.sync="emailReviewOpen" :destroy-on-close="true" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <emailReviewForm v-if="emailReviewOpen" ref="emailReviewForm" :show-btn-status="!useProcess" />
    </el-dialog>
    <!-- Hurdle测算 -->
    <el-dialog
      title="Hurdle测算"
      :visible.sync="hurdleOpen"
      :close-on-click-modal="false"
      :lock-scroll="false"
      :destroy-on-close="true"
      custom-class="dialogView"
      append-to-body
    >
      <fundLpIncomeMeasure ref="fundLpIncomeMeasure" />
    </el-dialog>
  </div>
</template>

<script>
import {
  allocationCalculate,
  delFundFpMain,
  exportFundFpMain,
  getFundLossList,
  listFundFpMain,
  getFundFpMainSum
} from '@/api/fund/fp/fundFpMain'
import wordOnlineTemplateForm from '@/views/system/word/template/wordOnlineTemplateForm.vue'
import fundFpMainForm from './fundFpMainForm.vue'
import fundLpIncomeMeasure from '../investor/fundLpIncomeMeasure.vue'
import fundFundFpSourceList from './fundFundFpSourceList.vue'
import fundFpGroupInvestor from './fundFpGroupInvestor.vue'
import fundFpLossDealList from './fundFpLossDealList.vue'
import afficheForm from '@/views/fund/lpBase/lp/afficheForm.vue'
import afficheTemplateForm from '@/views/fund/lpBase/lp/afficheTemplateForm.vue'
import wordOnlineTemplateList from '@/views/system/word/template/wordOnlineTemplateList.vue'
import emailReviewForm from '@/views/fund/lpBase/lp/EmailReviewForm'
import { getToken } from '@/utils/auth'
import { getMenuProcess } from '@/api/act/process/wfMenuProcess'
import { checkIsTemplate, saveWordSetCustomTemplate } from '@/api/system/word/template/wordOnlineTemplate'
import { existBusinessId } from '@/api/fund/lpBase/lp/affiche/afficheListTemplate'
import { getFundBase } from '@/api/fund/fundBase'

export default {
  components: {
    afficheForm,
    emailReviewForm,
    wordOnlineTemplateForm,
    wordOnlineTemplateList,
    afficheTemplateForm,
    fundFpMainForm,
    fundFundFpSourceList,
    fundFpGroupInvestor,
    fundFpLossDealList,
    fundLpIncomeMeasure
  },
  data() {
    return {
      otherBtnHide: false,
      hurdleOpen: false,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 基金分配主表表格数据
      fundFpMainList: [],
      fundFpMainSum: {},
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      formFpOpen: false,
      // 查看详情弹出层
      detailsOpen: false,
      // 查看详情弹出层标题
      detailsTitle: '',
      // 查看详情弹出层
      detailsGroupOpen: false,
      // 查看详情弹出层标题
      detailsGroupTitle: '',
      // 查看补亏列表弹出层
      lossOpen: false,
      // 查看补亏弹出层标题
      lossTitle: '',
      // 分配类型字典
      fpTypeOptions: [],
      // 分配方式字典
      fpWayOptions: [],
      // 币种字典
      currencyOptions: [],
      publicityOpen: false,
      callInitStatus: true,
      // 公告按钮可见
      showAfficheSaveBtn: true,
      // 查询参数
      queryParams: {
        fundId: this.$route.query.id,
        fpType: undefined,
        fpQc: undefined,
        fpWay: undefined,
        investorShareWay: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fpQc: [{
          required: true,
          message: this.$t('必填信息'),
          trigger: 'blur'
        }]
      },
      // 分配详情导入参数
      upload: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: '',
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: 'Bearer ' + getToken(), fundId: this.$route.query.id, fpQc: '' },
        // headers: {},
        // 上传的地址
        url: ''
      },
      // 是否配置了流程
      useProcess: false,
      menuKey: 'fund_fp',
      fpQc: undefined,
      fpQcList: [],
      emailReviewOpen: false,
      templateOpen: false,
      keyWordTitle: '',
      keyWordFormLoading: false,
      keyWordLoading: false,
      url: process.env.VUE_APP_BASE_API + '/fp/fundFpDetails/importDetailData'
    }
  },
  created() {
    this.getList()
    this.getUseProcess()
    this.getDicts('fund_fp_type').then(response => {
      this.fpTypeOptions = response.data
    })
    this.getDicts('fund_fp_way').then(response => {
      this.fpWayOptions = response.data
    })
    this.getDicts('fund_share_way').then(response => {
      this.investorShareWayOptions = response.data
    })
    this.initData(null)
  },
  methods: {
    /** 查询基金分配主表列表 */
    getList() {
      this.loading = true
      getFundFpMainSum(this.queryParams).then(response => {
        this.fundFpMainSum = response.data
      })
      listFundFpMain(this.queryParams).then(response => {
        this.fundFpMainList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 获取是否使用流程
    getUseProcess() {
      // 根据基金ID区分使用基金流程还是SPV流程
      getFundBase(this.$route.query.id).then(res => {
        if (res && !this.isEmpty(res.data)) {
          if (res.data.dataType === 'spv' || res.data.dataType === 'SPV') {
            this.menuKey = 'fund_fp_spv'
          }
        }
        getMenuProcess(this.menuKey).then(response => {
          this.useProcess = (response.data !== undefined && response.data !== null && response.data !== '')
        })
      })
    },
    // 分配类型字典翻译
    fpTypeFormat(row) {
      var result = ''
      var fpType = row.fpType
      if (fpType !== undefined && fpType !== null && fpType !== '') {
        fpType = fpType.split(',')
        result = []
        fpType.forEach(item => {
          result.push(this.selectDictLabel(this.fpTypeOptions, item))
        })
        result = result.join(',')
      }
      return result
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        fundId: this.$route.query.id,
        fpType: undefined,
        fpQc: undefined,
        fpTime: undefined,
        fpTotalAmount: undefined,
        currency: undefined,
        interestRate: undefined,
        interestDay: undefined,
        balanceLp: undefined,
        catchClauseLp: undefined,
        fpWay: undefined,
        investorShareWay: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined,
        remark: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formFpOpen = true
      this.title = this.$t('基金分配')
      this.$nextTick(() => {
        this.$refs.fundFpMainForm.init(null)
      })
    },
    /** 查看详情 */
    openDetails(row) {
      this.detailsGroupOpen = true
      this.detailsGroupTitle = this.$t('基金分配详情')
      this.otherBtnHide = row.actStatus === 'W' || row.actStatus === 'D'
      this.$nextTick(() => {
        this.$refs.fundFpGroupInvestor.listDetailGroupInvestor(row)
      })
      /* this.detailsOpen = true
      this.detailsTitle = this.$t('基金分配详情')
      this.$nextTick(() => {
        this.$refs.fundFundFpSourceList.getFundFpSourceList(row)
      }) */
    },
    /** 分配计算 */
    allocation(row) {
      var _this = this
      this.$confirm(this.$t('是否确认分配计算?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        getFundLossList(row.id).then(response => {
          if (response.total > 0) {
            _this.lossOpen = true
            _this.lossTitle = _this.$t('待补亏项目列表')
            _this.$nextTick(() => {
              _this.$refs.fundFpLossDealList.getFundLossDealList(row)
            })
          } else {
            _this.loading = true
            allocationCalculate(row.id).then(() => {
              _this.loading = false
              _this.msgSuccess(_this.$t('分配计算成功'))
            })
          }
        })
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formFpOpen = true
      this.title = this.$t('基金分配')
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.fundFpMainForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(() => {
        this.loading = true
        return delFundFpMain(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(function() {
      })
    },
    /** 导出按钮操作 */
    exportHandle() {
      const queryParams = this.queryParams
      this.$confirm(this.$t('是否确认导出?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return exportFundFpMain(queryParams)
      }).then(response => {
        this.download(response.msg)
      }).catch(function() {
      })
    },
    // 下载模板
    fetchTemplate() {
      var href1 = window.location.href
      var href2 = this.$route.path
      var url = href1.substring(0, href1.indexOf(href2))
      window.location.href = url + '/template/detailsOfTheFundsAllocated(new)ImportTemplate.xlsx'
    },
    // 文件上传中处理
    handleFileUploadProgress() {
      this.upload.isUploading = true
    },
    // 文件上传成功处理
    handleFileSuccess(response) {
      console.log(response)
      this.upload.open = false
      this.upload.isUploading = false
      this.$refs.upload.clearFiles()
      if (response.msg === 'success') {
        this.msgSuccess(this.$t('导入成功'))
        this.upload.headers.fpQc = undefined
      } else if (response.code === 500) {
        this.msgError(this.$t('数据异常'))
      } else {
        this.$alert(response.msg, this.$t('导入结果'), { dangerouslyUseHTMLString: true })
      }
      this.getList()
    },
    // 提交上传文件
    submitFileForm() {
      if (this.upload.headers.fpQc === null || this.upload.headers.fpQc === undefined ||
        this.upload.headers.fpQc === '') {
        this.msgError('请选择分配批次')
        return
      }
      this.upload.url = this.url + '?fpQc=' + this.upload.headers.fpQc
      this.$nextTick(() => {
        console.log(this.upload.headers.fpQc)
        this.$refs.upload.submit()
      })
    },
    // 文件达到上限处理
    handleFileExceed() {
      this.msgError(this.$t('可上传文件数量已达到上限'))
    },
    // 配置公告
    sendHandle(row) {
      this.publicityOpen = true
      this.showAfficheSaveBtn = !(row.actStatus === 'W' || row.actStatus === 'D')
      this.$nextTick(() => {
        if (row.announcementId !== undefined && row.announcementId !== null && row.announcementId !== '') {
          // 判断当前基金是否存在模板不存在取默认的
          var fundId = this.$route.query.id === undefined ? this.queryParams.fundId : this.$route.query.id
          fundId = (fundId === undefined || fundId === '' || fundId === null) ? this.selectCallFundId : fundId
          existBusinessId({ businessId: fundId, businessType: 'fundFpMain', orgId: '4' }).then(response => {
            if (response.data) {
              this.$refs.afficheForm.init({ id: row.announcementId, fundId: row.fundId, type: response.data.id, period: row.id, dataId: row.id })
            } else {
              this.$refs.afficheForm.init({ id: row.announcementId, fundId: row.fundId, type: '4', period: row.id, dataId: row.id })
            }
          })
        } else {
          this.updateSendHandle(row)
        }
      })
    },
    updateSendHandle(row) {
      // 判断当前基金是否存在模板不存在取默认的
      var fundId = this.$route.query.id === undefined ? this.queryParams.fundId : this.$route.query.id
      fundId = (fundId === undefined || fundId === '' || fundId === null) ? this.selectCallFundId : fundId
      existBusinessId({ businessId: fundId, businessType: 'fundFpMain', orgId: '4' }).then(response => {
        if (response.data) {
          this.$refs.afficheForm.reset()
          this.$refs.afficheForm.form.fundId = row.fundId
          this.$refs.afficheForm.form.type = response.data.id
          this.$refs.afficheForm.displayNone = { period: true, fundScale: false, callProp: false, callMoney: false }
          this.$refs.afficheForm.form.period = row.id
          this.$refs.afficheForm.form.periodTemp = row.id
          this.$refs.afficheForm.dataChange(row.fundId)
          this.$refs.afficheForm.changeType(response.data.id)
          this.$refs.afficheForm.showFpInvestor(row.id)
        }
      })
    },
    // 审核公告
    noticeHandle(row) {
      this.emailReviewOpen = true
      this.$nextTick(() => {
        this.$refs.emailReviewForm.init({ id: row.announcementId })
      })
    },
    notNullAfffiche(row) {
      this.publicityOpen = false
      setTimeout(() => {
        this.callInitStatus = true
        this.publicityOpen = true
        this.$nextTick(() => {
          row.id = row.dataId
          this.updateSendHandle(row)
        })
      }, 100)
    },
    // 通知模板
    setMessageTemplate() {
      this.templateOpen = true
      this.$nextTick(() => {
        // 判断当前基金是否存在模板不存在取默认的
        var fundId = this.$route.query.id === undefined ? this.queryParams.fundId : this.$route.query.id
        fundId = (fundId === undefined || fundId === '' || fundId === null) ? this.selectCallFundId : fundId
        existBusinessId({ businessId: fundId, businessType: 'fundFpMain', orgId: '4' }).then(response => {
          console.log(response)
          if (response.data) {
            this.$refs.afficheTemplateForm.init({ id: response.data.id })
          } else {
            this.$refs.afficheTemplateForm.init({ id: '4' })
          }
        })
      })
    },
    // 设置模板
    setTemplate() {
      console.log('打开模板列表')
      var fundId = this.$route.query.id === undefined ? this.queryParams.fundId : this.$route.query.id
      fundId = (fundId === undefined || fundId === '' || fundId === null) ? this.selectCallFundId : fundId
      if (fundId) {
        this.keyWordLoading = true
        this.keyWordTitle = this.$t('模板列表')
        this.$nextTick(() => {
          this.$refs.wordOnlineTemplateList.textReminder = '模板中必须包含 "&{出资人名称}" 关键字'
          this.$refs.wordOnlineTemplateList.queryParams.templateType = 'JJFPTZ'
          this.$refs.wordOnlineTemplateList.externalCallTemplateStatus = true
          this.$refs.wordOnlineTemplateList.getList()
        })
      } else {
        this.queryParamsRules.fundId = [{ required: true, message: this.$t('先选择一支基金'), trigger: ['change', 'blur'] }]
        this.$refs['queryForm'].validate()
      }
    },
    // 保存选定的模板
    saveSelectTemplate(that, row) {
      console.log(row)
      that.loading = true
      const type = that.queryParams.templateType
      var fundId = this.$route.query.id === undefined ? this.queryParams.fundId : this.$route.query.id
      fundId = (fundId === undefined || fundId === '' || fundId === null) ? this.selectCallFundId : fundId
      saveWordSetCustomTemplate({ businessId: fundId, businessType: 'fund', templateId: row.id, keyWord: row.customValue, templateType: type }).then(response => {
        console.log(response)
        if (response.code === 200) {
          this.msgSuccess(response.msg)
          // 关闭页面
          this.keyWordLoading = false
        } else {
          this.msgError(response.msg)
        }
        that.loading = false
      })
    },
    // 基金分配
    async generateFpNoticeByFundFp(row, callBack) {
      console.log('generateFpNoticeByFundFp1')
      var fundId = this.$route.query.id === undefined ? this.queryParams.fundId : this.$route.query.id
      fundId = (fundId === undefined || fundId === '' || fundId === null) ? this.selectCallFundId : fundId
      await checkIsTemplate(fundId, 'fund', 'JJFPTZ').then(response => {
        if (response.data === null) {
          this.msgError(this.$t('请先设置模板!'))
        } else {
          this.keyWordFormLoading = true
          this.$nextTick(() => {
            console.log('generateFpNoticeByFundFp2 - > 进入模板调用页面')
            this.$refs.wordOnlineTemplateForm.initFundFpBatch(response.data, row, fundId, callBack)
          })
        }
      })
    },
    // 关闭模板form页面
    templateFormCancel() {
      this.keyWordFormLoading = false
    },
    initData(val) {
      if (val === 1) {
        this.upload.open = true
      }
      listFundFpMain({ fundId: this.$route.query.id }).then(response => {
        this.fpQcList = response.rows
      })
    },
    // 合计
    getSummaries(param) {
      const { columns } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
        } else if (index === 3) {
          sums[index] = this.moneyFormat(this.fundFpMainSum.fpTotalAmount, 'w')
        } else if (index === 4) {
          sums[index] = this.moneyFormat(this.fundFpMainSum.totalAllocationDetails, 'w')
        } else {
          sums[index] = ''
        }
      })
      return sums
    }

  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.tipText{
  color: #555;
}
/deep/.dialogFormCustom {
  display: none;
}
</style>
